<?php

	class Comments extends ActiveRecord {
        var $allowed_html;
        
        function _setup()
        {
            $this->table = DB_PREFIX.'comments';
        }

		function validate()
		{
			$this->validates_presence_of(array(
										'news_id',
										'author',
										'author_email',
										'author_url',
										'author_ip',
										'content',
										'user_agent'));
			$this->validates_as_email('email');
		}
		
		function after_validation()
        {                    
            $content = $this->get('content');
            if(empty($content)) return;
            require VENDOR.'/htmlpurifier/HTMLPurifier.auto.php';
            $config = HTMLPurifier_Config::createDefault();
            $config->set('Core', 'Encoding', DEFAULT_CHARSET); //replace with your encoding
            $config->set('HTML','Doctype',HTML_DOCTYPE);
            $purifier = new HTMLPurifier($config);

            $clean_html = $purifier->purify($this->get('content'));
            $this->set('content',$clean_html);
            
        }
	}

?>